<?php
declare (strict_types = 1);

namespace app\admin\controller;
use app\admin\model\SettingModel;
class Setting extends Base
{
    public function index(){
    	$setting=SettingModel::setSetting();
        if(request()->isPost()){
        	$data=request()->post();
        	$update=[];
        	foreach ($data as $k => $v) {
        		foreach ($v as $key => $value) {
        			$update[]=['id'=>$setting[$k][$key]['id'],'value'=>$value];
        		}
        	}
        	if(!empty($update)){
        		(new SettingModel)->saveAll($update);
        	}
        	SettingModel::setSetting();
            return $this->success('修改成功');
        }
        
        $this->assign(['setting'=>$setting]);
        return $this->fetch();
    }    
}
